package main.java.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.gender,c.name,c.floor\n" +
                    "FROM class c\n" +
                    "JOIN teacher t ON c.teacher_id = t.id\n" +
                    "WHERE t.name = '王克晶'";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                String name = rs.getString("t.name");
                String gender = rs.getString("t.gender");
                String class_name = rs.getString("c.name");
                int floor = rs.getInt("c.floor");
                System.out.println(name+"，"+gender+"，"+class_name+"，"+floor);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
